.class public Lcom/nemustech/tiffany/util/TFCache;
.super Ljava/lang/Object;
.source "TFCache.java"


# static fields
.field private static final TAG:Ljava/lang/String; = "TFCache"

.field public static final VICTIM_STYLE_NEW:I = 0x1

.field public static final VICTIM_STYLE_OLD:I


# instance fields
.field private mArrayBitmap:Ljava/util/LinkedHashMap;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/LinkedHashMap",
            "<",
            "Ljava/lang/Integer;",
            "Landroid/graphics/Bitmap;",
            ">;"
        }
    .end annotation
.end field

.field private mArrayIntKey:Ljava/util/LinkedList;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/LinkedList",
            "<",
            "Ljava/lang/Integer;",
            ">;"
        }
    .end annotation
.end field

.field private mArrayStrKey:Ljava/util/LinkedHashMap;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/LinkedHashMap",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/Integer;",
            ">;"
        }
    .end annotation
.end field

.field private mCapacity:I

.field private mPseudoId:I

.field private mVictimShouldBeOldestOne:Z


# direct methods
.method public constructor <init>(I)V
    .locals 2
    .parameter "maxCacheCount"

    .prologue
    .line 20
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 21
    iput p1, p0, Lcom/nemustech/tiffany/util/TFCache;->mCapacity:I

    .line 22
    new-instance v0, Ljava/util/LinkedHashMap;

    iget v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mCapacity:I

    invoke-direct {v0, v1}, Ljava/util/LinkedHashMap;-><init>(I)V

    iput-object v0, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    .line 23
    new-instance v0, Ljava/util/LinkedList;

    invoke-direct {v0}, Ljava/util/LinkedList;-><init>()V

    iput-object v0, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    .line 24
    new-instance v0, Ljava/util/LinkedHashMap;

    invoke-direct {v0}, Ljava/util/LinkedHashMap;-><init>()V

    iput-object v0, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    .line 25
    return-void
.end method

.method private removeVictim()V
    .locals 3

    .prologue
    .line 123
    iget-boolean v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mVictimShouldBeOldestOne:Z

    if-eqz v2, :cond_0

    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v2}, Ljava/util/LinkedList;->removeFirst()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/Integer;

    move-object v0, v2

    .line 124
    .local v0, key:Ljava/lang/Integer;
    :goto_0
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v2}, Ljava/util/LinkedHashMap;->values()Ljava/util/Collection;

    move-result-object v2

    invoke-interface {v2, v0}, Ljava/util/Collection;->remove(Ljava/lang/Object;)Z

    .line 126
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, v0}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Landroid/graphics/Bitmap;

    .line 128
    .local v1, victim:Landroid/graphics/Bitmap;
    invoke-virtual {v1}, Landroid/graphics/Bitmap;->recycle()V

    .line 129
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, v0}, Ljava/util/LinkedHashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 130
    return-void

    .line 123
    .end local v0           #key:Ljava/lang/Integer;
    .end local v1           #victim:Landroid/graphics/Bitmap;
    :cond_0
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v2}, Ljava/util/LinkedList;->removeLast()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/Integer;

    move-object v0, v2

    goto :goto_0
.end method


# virtual methods
.method public add(ILjava/lang/String;Landroid/graphics/Bitmap;)V
    .locals 5
    .parameter "location"
    .parameter "string"
    .parameter "bitmap"

    .prologue
    .line 55
    invoke-virtual {p0}, Lcom/nemustech/tiffany/util/TFCache;->getCachedCount()I

    move-result v2

    iget v3, p0, Lcom/nemustech/tiffany/util/TFCache;->mCapacity:I

    if-lt v2, v3, :cond_0

    .line 56
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v2}, Ljava/util/LinkedList;->removeLast()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Integer;

    .line 57
    .local v0, key:Ljava/lang/Integer;
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v2}, Ljava/util/LinkedHashMap;->values()Ljava/util/Collection;

    move-result-object v2

    invoke-interface {v2, v0}, Ljava/util/Collection;->remove(Ljava/lang/Object;)Z

    .line 58
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, v0}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Landroid/graphics/Bitmap;

    .line 59
    .local v1, victim:Landroid/graphics/Bitmap;
    invoke-virtual {v1}, Landroid/graphics/Bitmap;->recycle()V

    .line 60
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, v0}, Ljava/util/LinkedHashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 62
    .end local v0           #key:Ljava/lang/Integer;
    .end local v1           #victim:Landroid/graphics/Bitmap;
    :cond_0
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, p2}, Ljava/util/LinkedHashMap;->containsKey(Ljava/lang/Object;)Z

    move-result v2

    if-eqz v2, :cond_1

    .line 63
    new-instance v2, Ljava/lang/IllegalArgumentException;

    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    const-string v4, "Cache manager has already that string key! : "

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v2

    .line 65
    :cond_1
    new-instance v0, Ljava/lang/Integer;

    iget v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mPseudoId:I

    add-int/lit8 v3, v2, 0x1

    iput v3, p0, Lcom/nemustech/tiffany/util/TFCache;->mPseudoId:I

    invoke-direct {v0, v2}, Ljava/lang/Integer;-><init>(I)V

    .line 66
    .restart local v0       #key:Ljava/lang/Integer;
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v2, p1, v0}, Ljava/util/LinkedList;->add(ILjava/lang/Object;)V

    .line 67
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, v0, p3}, Ljava/util/LinkedHashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 68
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, p2, v0}, Ljava/util/LinkedHashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 69
    return-void
.end method

.method public clear()V
    .locals 4

    .prologue
    .line 133
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v3}, Ljava/util/LinkedList;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, i$:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_0

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/Integer;

    .line 134
    .local v2, integer:Ljava/lang/Integer;
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v3, v2}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/graphics/Bitmap;

    .line 135
    .local v0, bitmap:Landroid/graphics/Bitmap;
    invoke-virtual {v0}, Landroid/graphics/Bitmap;->recycle()V

    goto :goto_0

    .line 138
    .end local v0           #bitmap:Landroid/graphics/Bitmap;
    .end local v2           #integer:Ljava/lang/Integer;
    :cond_0
    const/4 v3, 0x0

    iput v3, p0, Lcom/nemustech/tiffany/util/TFCache;->mPseudoId:I

    .line 139
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v3}, Ljava/util/LinkedHashMap;->clear()V

    .line 141
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v3}, Ljava/util/LinkedList;->clear()V

    .line 142
    iget-object v3, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v3}, Ljava/util/LinkedHashMap;->clear()V

    .line 143
    return-void
.end method

.method public get(I)Landroid/graphics/Bitmap;
    .locals 3
    .parameter "id"

    .prologue
    .line 100
    new-instance v1, Ljava/lang/Integer;

    invoke-direct {v1, p1}, Ljava/lang/Integer;-><init>(I)V

    .line 101
    .local v1, key:Ljava/lang/Integer;
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, v1}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/graphics/Bitmap;

    .line 102
    .local v0, bitmap:Landroid/graphics/Bitmap;
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, v1}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Landroid/graphics/Bitmap;

    return-object p0
.end method

.method public get(Ljava/lang/String;)Landroid/graphics/Bitmap;
    .locals 2
    .parameter "string"

    .prologue
    .line 106
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v1, p1}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Integer;

    .line 107
    .local v0, key:Ljava/lang/Integer;
    if-nez v0, :cond_0

    .line 108
    const/4 v1, 0x0

    .line 110
    :goto_0
    return-object v1

    :cond_0
    invoke-virtual {v0}, Ljava/lang/Integer;->intValue()I

    move-result v1

    invoke-virtual {p0, v1}, Lcom/nemustech/tiffany/util/TFCache;->get(I)Landroid/graphics/Bitmap;

    move-result-object v1

    goto :goto_0
.end method

.method public getCachedCount()I
    .locals 1

    .prologue
    .line 114
    iget-object v0, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v0}, Ljava/util/LinkedHashMap;->size()I

    move-result v0

    return v0
.end method

.method public indexOf(Ljava/lang/String;)I
    .locals 2
    .parameter "string"

    .prologue
    .line 87
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v1, p1}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Integer;

    .line 88
    .local v0, key:Ljava/lang/Integer;
    if-eqz v0, :cond_0

    .line 89
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v1, v0}, Ljava/util/LinkedList;->indexOf(Ljava/lang/Object;)I

    move-result v1

    .line 91
    :goto_0
    return v1

    :cond_0
    const/4 v1, -0x1

    goto :goto_0
.end method

.method public put(ILandroid/graphics/Bitmap;)Ljava/lang/Integer;
    .locals 4
    .parameter "id"
    .parameter "bitmap"

    .prologue
    .line 29
    invoke-virtual {p0}, Lcom/nemustech/tiffany/util/TFCache;->getCachedCount()I

    move-result v1

    iget v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mCapacity:I

    if-lt v1, v2, :cond_0

    invoke-direct {p0}, Lcom/nemustech/tiffany/util/TFCache;->removeVictim()V

    .line 31
    :cond_0
    new-instance v0, Ljava/lang/Integer;

    invoke-direct {v0, p1}, Ljava/lang/Integer;-><init>(I)V

    .line 33
    .local v0, key:Ljava/lang/Integer;
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v1, v0}, Ljava/util/LinkedHashMap;->containsKey(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_1

    .line 34
    new-instance v1, Ljava/lang/IllegalArgumentException;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "Cache manager has already that key! : "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 36
    :cond_1
    iget-boolean v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mVictimShouldBeOldestOne:Z

    if-eqz v1, :cond_2

    .line 37
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v1, v0}, Ljava/util/LinkedList;->addLast(Ljava/lang/Object;)V

    .line 41
    :goto_0
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v1, v0, p2}, Ljava/util/LinkedHashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 44
    return-object v0

    .line 39
    :cond_2
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v1, v0}, Ljava/util/LinkedList;->addFirst(Ljava/lang/Object;)V

    goto :goto_0
.end method

.method public put(Ljava/lang/String;Landroid/graphics/Bitmap;)V
    .locals 4
    .parameter "string"
    .parameter "bitmap"

    .prologue
    .line 48
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v1, p1}, Ljava/util/LinkedHashMap;->containsKey(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_0

    .line 49
    new-instance v1, Ljava/lang/IllegalArgumentException;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "Cache manager has already that string key! : "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 50
    :cond_0
    iget v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mPseudoId:I

    add-int/lit8 v2, v1, 0x1

    iput v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mPseudoId:I

    invoke-virtual {p0, v1, p2}, Lcom/nemustech/tiffany/util/TFCache;->put(ILandroid/graphics/Bitmap;)Ljava/lang/Integer;

    move-result-object v0

    .line 51
    .local v0, key:Ljava/lang/Integer;
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v1, p1, v0}, Ljava/util/LinkedHashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 52
    return-void
.end method

.method public remove(Ljava/lang/Integer;)V
    .locals 3
    .parameter "value"

    .prologue
    .line 78
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v2, p1}, Ljava/util/LinkedList;->indexOf(Ljava/lang/Object;)I

    move-result v0

    .line 79
    .local v0, location:I
    const/4 v2, -0x1

    if-eq v0, v2, :cond_0

    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v2}, Ljava/util/LinkedList;->size()I

    move-result v2

    if-ge v0, v2, :cond_0

    .line 80
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayIntKey:Ljava/util/LinkedList;

    invoke-virtual {v2, v0}, Ljava/util/LinkedList;->remove(I)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/Integer;

    .line 81
    .local v1, removedValue:Ljava/lang/Integer;
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v2}, Ljava/util/LinkedHashMap;->values()Ljava/util/Collection;

    move-result-object v2

    invoke-interface {v2, v1}, Ljava/util/Collection;->remove(Ljava/lang/Object;)Z

    .line 82
    iget-object v2, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayBitmap:Ljava/util/LinkedHashMap;

    invoke-virtual {v2, v1}, Ljava/util/LinkedHashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 84
    .end local v1           #removedValue:Ljava/lang/Integer;
    :cond_0
    return-void
.end method

.method public remove(Ljava/lang/String;)V
    .locals 2
    .parameter "string"

    .prologue
    .line 72
    iget-object v1, p0, Lcom/nemustech/tiffany/util/TFCache;->mArrayStrKey:Ljava/util/LinkedHashMap;

    invoke-virtual {v1, p1}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Integer;

    .line 73
    .local v0, key:Ljava/lang/Integer;
    if-eqz v0, :cond_0

    .line 74
    invoke-virtual {p0, v0}, Lcom/nemustech/tiffany/util/TFCache;->remove(Ljava/lang/Integer;)V

    .line 75
    :cond_0
    return-void
.end method

.method public setVictimStyle(I)V
    .locals 1
    .parameter "victimStyle"

    .prologue
    .line 118
    if-nez p1, :cond_0

    const/4 v0, 0x1

    :goto_0
    iput-boolean v0, p0, Lcom/nemustech/tiffany/util/TFCache;->mVictimShouldBeOldestOne:Z

    .line 120
    return-void

    .line 118
    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method
